﻿using Dapper;
using Microsoft.Extensions.Options;
using orders.Entitys;
using orders.Model;
using System.Collections.Generic;
using System.Data;
using System.Linq;

namespace orders.Repository.Impl
{
    public class OrderRepository :BaseRepository<Order>, IOrderRepository 
    {

        public OrderRepository(IDataSource dataSource) : base(dataSource)
        {
        }

        public List<OrderDetail> GetOrderDetails()
        {
            var sql = $@" 
                    SELECT top(20)
                           max(goodsno) as  OrderNo
                          ,SUM(goodsprice*totalamount) as SumPrice
                          ,sum(totalamount) as TotalAmount
                        , dbo.AggregateString(goodsno) as Colors
                      FROM [dbo].[orders]  group by  goodsno";
            
            return _connection.Query<OrderDetail>(sql).ToList();
        }
     
    }
}
